package com.stylefeng.guns.modular.vpn_server_info.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.common.constant.DatasourceEnum;
import com.stylefeng.guns.core.common.exception.BizExceptionEnum;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.mutidatasource.annotion.DataSource;
import com.stylefeng.guns.modular.system.dao.VpnAllowIpMapper;
import com.stylefeng.guns.modular.vpn.utils.ServerIPUtil;
import com.stylefeng.guns.modular.vpn_server_info.entity.AllowIp;
import com.stylefeng.guns.modular.vpn_server_info.entity.VpnServerDTO;
import com.stylefeng.guns.modular.vpn_server_info.service.IVpnAllowIpService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class VpnAllowIpServiceImpl extends ServiceImpl<VpnAllowIpMapper, AllowIp> implements IVpnAllowIpService {

    @Override
    @DataSource(name = DatasourceEnum.DATA_SOURCE_BIZ)
    public void insertAllowIPs(VpnServerDTO vpnServerDTO) {
        log.info("添加VPN服务器AllowIP网段 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        super.insertBatch(ServerIPUtil.getAllowIPs(vpnServerDTO)
                .orElseThrow(() -> new  GunsException(BizExceptionEnum.VPN_ALLOW_IP_FAIL)));
    }
}
